using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SMWJamecl.BusinessEntities;

namespace SMWJamecl.Repository.Mapping
{
    public class DetalleAlquilerMap : EntityTypeConfiguration<DetalleAlquiler>
    {
        public DetalleAlquilerMap()
        {
            // Primary Key
            this.HasKey(t => new { t.Placa, t.Id_Accesorio });

            // Properties
            this.Property(t => t.Placa)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(7);

            this.Property(t => t.Id_Accesorio)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.CostoChofer)
                .IsFixedLength()
                .HasMaxLength(10);

            this.Property(t => t.CostoVehiculo)
                .IsFixedLength()
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("DetalleAlquiler");
            this.Property(t => t.Placa).HasColumnName("Placa");
            this.Property(t => t.Id_Accesorio).HasColumnName("Id_Accesorio");
            this.Property(t => t.Alquiler_id).HasColumnName("Alquiler_id");
            this.Property(t => t.Chofer).HasColumnName("Chofer");
            this.Property(t => t.CostoChofer).HasColumnName("CostoChofer");
            this.Property(t => t.CostoVehiculo).HasColumnName("CostoVehiculo");

            // Relationships
            this.HasRequired(t => t.Alquiler)
                .WithMany(t => t.DetalleAlquilers)
                .HasForeignKey(d => d.Alquiler_id);
            this.HasRequired(t => t.Equipo)
                .WithOptional(t => t.DetalleAlquiler);

        }
    }
}
